package com.dolawing.phonecallapp.listenphonecall;

import android.util.Log;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class TimeUtils {
    /**
     * 今天  2022-04-10 11:20:34
     * @return
     */
    public static String getTodayTime(){
        Calendar calendar =  Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(calendar.getTime());
       // Log.i("TodayTime",time);
        return time;
    }

    /**
     * 今天  2022-04-10 00:00:00
     * @return
     */
    public static String getTodayFormatTime(){
        Calendar calendar =  Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String time = sdf.format(calendar.getTime());
       // Log.i("TodayTime",time);
        return time;
    }
    /**
     * 今天  2022-04-09 00:00:00
     * @return
     */
    public static String getYesterdayFormatTime(){
        Calendar calendar =  Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
        calendar.add(Calendar.DAY_OF_YEAR, -1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String time = sdf.format(calendar.getTime());
       // Log.i("YesterdayTime",time);
        return time;
    }

    /**
     * 获取任何一天 2022-04-09 00:00:00
     * @param day
     * @return
     */
    public static String getAnyDayFormatTime(int day){
        Calendar calendar =  Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
        calendar.add(Calendar.DAY_OF_YEAR, day);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String time = sdf.format(calendar.getTime());
       // Log.i("AnydayTime",time);
        return time;
    }

    /**
     * 获取任何一天 2022-04-09
     * @param day
     * @return
     */
    public static String getAnyDayFormat2Time(int day){
        Calendar calendar =  Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
        calendar.add(Calendar.DAY_OF_YEAR, day);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String time = sdf.format(calendar.getTime());
       // Log.i("AnydayTime",time);
        return time;
    }

    /**
     * 将 字符串 时间 转化为 数值型时间
     * @param times
     * @return
    */
    public static long tranStringTimeTotimestamp(String times){
        DateFormat df = new SimpleDateFormat("HH:mm");
        long timestamps = 0;
        try {
            Date date = df.parse(times);
            timestamps = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timestamps;
    }

    /**
     * 将字符串日期 转化为 整数
     */
    public static long tranStringDateToDatestamp(String stringDate)  {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        long timestamps = 0;
        try {
            timestamps= df.parse(stringDate).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timestamps;
    }

    /**
     * 将 字符串日期 转化为 整数
     * @param datetimeString
     * @return
     */
    public static long tranStringDateTimeToTimestamp(String datetimeString){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long timestamps = 0;
        try {
            timestamps = sdf.parse(datetimeString).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timestamps;
    }



    /**
     * 将 字符串日期 转化为 日期格式
     * @param datetime
     * @return
     */
    public static Date tranStringDatetimeToDate(String datetime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = sdf.parse(datetime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 将 数字型 时间戳 转化为 日期字符串
     * @param timestamps
     * @return
     */
    public static String tranTimestampToStringDate(long timestamps){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date(timestamps));
    }

}
